﻿// <copyright file="DataTableExtensionsTest.cs" company="DotNetLib">
//
// .netlib: http://www.codeplex.com/DotNetLib
//
// This code is released under the New BSD License.
// A copy of this license is available at:
// http://www.codeplex.com/DotNetLib/license
//
// </copyright>

namespace DotNetLib.Tests
{
  using System.Data;
  using System.IO;
  using DotNetLib.Data;
  using global::Microsoft.VisualStudio.TestTools.UnitTesting;

  [TestClass()]
  public class DataTableExtensionsTest
  {
    [TestMethod()]
    public void TestReadCsv()
    {
      DataTable dt = new DataTable();
      using (StringReader reader = new StringReader(Properties.Resources.SampleCsv))
      {
        dt.ReadCsv(reader, true);
      }

      Assert.AreEqual(3, dt.Columns.Count);
      Assert.AreEqual("Result", dt.Columns[0].ColumnName);
      Assert.AreEqual("Date, Time", dt.Columns[1].ColumnName);
      Assert.AreEqual("Number", dt.Columns[2].ColumnName);

      Assert.AreEqual(3, dt.Rows.Count);
      Assert.AreEqual("Invalid Number", dt.Rows[0][0].ToString());
      Assert.AreEqual("2009/07/23 17:37:20", dt.Rows[0][1].ToString());
      Assert.AreEqual("16669995555", dt.Rows[0][2].ToString());

      Assert.AreEqual("Connection, Refused", dt.Rows[1][0].ToString());
      Assert.AreEqual("2009/07/23 17:36:49", dt.Rows[1][1].ToString());
      Assert.AreEqual("15556669999", dt.Rows[1][2].ToString());

      Assert.AreEqual("Connection Refused", dt.Rows[2][0].ToString());
      Assert.AreEqual("2009/07/23 17:40:53", dt.Rows[2][1].ToString());
      Assert.AreEqual("19995556666", dt.Rows[2][2].ToString());
    }
  }
}
